package com.ss.android.article.base.feature.d;

import android.content.Context;
import android.content.DialogInterface;
import android.content.Intent;
import android.os.Message;

import com.bytedance.common.utility.UIUtils;
import com.bytedance.common.utility.collection.WeakHandler;
import com.ss.android.article.browser.R;
import com.ss.android.common.app.IComponent;
import com.ss.android.common.dialog.AlertDialog;
import com.ss.android.common.util.NetworkUtils;
import com.ss.android.newmedia.BaseAppData;
import com.ss.android.newmedia.feedback.FeedbackActivity;
import com.ss.android.update.UpdateChecker;

import java.lang.ref.WeakReference;

public final class a implements WeakHandler.Callback {
    final Context mContext;
    final WeakHandler b;
    private final IComponent d;
    private final BaseAppData mBaseAppData;
    private final a$a f;
    WeakReference c;
    private UpdateChecker g;
    private WeakReference h;

    public a(Context arg2, IComponent arg3) {
        this(arg2, arg3, null);
    }

    public a(Context context, IComponent component, a$a arg5) {
        this.b = new WeakHandler(((WeakHandler.Callback) this));
        this.h = null;
        this.c = null;
        new b(this);
        this.mContext = context;
        this.mBaseAppData = BaseAppData.inst();
        this.d = component;
        this.f = arg5;
    }

    public final void startFeedbackActivity() {
        Intent intent = new Intent(this.mContext, FeedbackActivity.class);
        intent.putExtra("key_appkey", this.mBaseAppData.getAppContext().getFeedbackAppKey());
        intent.putExtra("use_swipe", true);
        this.mContext.startActivity(intent);
    }

    public final void b() {
        this.g = this.mBaseAppData.getUpdateChecker();
        UpdateChecker v0 = this.g;
        if (v0.c()) {
            com.ss.android.j.b.createDialogBuilder(this.mContext)
                    .setTitle(R.string.tip)
                    .setMessage(com.ss.android.article.browser.R.string.info_downloading)
                    .setPositiveButton(R.string.confirm, null)
                    .show();
        } else if (!NetworkUtils.isNetworkAvailable(this.mContext)) {
            com.ss.android.j.b.createDialogBuilder(this.mContext)
                    .setTitle(R.string.tip)
                    .setMessage(com.ss.android.article.browser.R.string.net_unvailable)
                    .setPositiveButton(R.string.confirm, null)
                    .show();
        } else {
            this.h = new WeakReference(com.ss.android.j.b.createDialogBuilder(this.mContext)
                    .setTitle(R.string.tip)
                    .setMessage(com.ss.android.article.browser.R.string.checking_update)
                    .setCancelable(false)
                    .show());
            new CheckVersionUpdateThread(this, "CheckVersionUpdate", v0).start();
        }
    }

    public final void handleMsg(Message message) {
        int v4 = R.string.tip;
        int v3 = R.string.confirm;
        DialogInterface.OnClickListener v2 = null;
        if (this.d.isViewValid()) {
            Object v1 = this.h != null ? this.h.get() : v2;
            Object v0 = this.c != null ? this.c.get() : v2;
            if (v1 != null) {
                ((AlertDialog) v1).dismiss();
            }

            if (v0 != null) {
                ((AlertDialog) v0).dismiss();
            }

            switch (message.what) {
                case 1: {
                    com.ss.android.j.b.createDialogBuilder(this.mContext).setTitle(v4).setMessage(com.ss.android.article.browser.R.string.net_error).setPositiveButton(v3, v2).show();
                    return;
                }
                case 2: {
                    com.ss.android.j.b.createDialogBuilder(this.mContext).setTitle(v4).setMessage(com.ss.android.article.browser.R.string.no_update_version).setPositiveButton(v3, v2).show();
                    if (this.f == null) {
                        return;
                    }

                    this.f.a();
                    return;
                }
                case 3: {
                    if (this.g != null && this.mContext != null) {
                        this.g.a(this.mContext, "more_tab", "update_version_confirm");
                    }

                    if (this.f == null) {
                        return;
                    }

                    this.f.a();
                    return;
                }
                case 4: {
                    UIUtils.showImageToast(this.mContext, R.drawable.doneicon_popup_textpage, R.string.toast_finish_clear);
                    if (this.f == null) {
                        return;
                    }

                    this.f.b();
                    return;
                }
            }

            return;
        }
    }

    public interface a$a {
        void a();

        void b();
    }
}

